package cn.shujuhai.cms.config.task;


import cn.shujuhai.cms.service.InfoArticleService;
import cn.shujuhai.common.aop.SysLogAspect;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: zhangDeZhong
 * @Date: 2024/12/19 11:01
 * @Description: 文章的定时发布任务
 **/
@Component
@RequiredArgsConstructor
public class ArticleScheduledTask {

    private final InfoArticleService infoArticleService;
    private static final Logger logger = LoggerFactory.getLogger(SysLogAspect.class);

    // 每分钟执行一次任务
    @Scheduled(cron = "0 * * * * ?")
    public void checkAndPublishArticles() {
        logger.info("开始执行任务：文章的定时发布");
        try {
            this.infoArticleService.doPendingArticles();
        } catch (Exception e) {
            logger.error("任务执行失败：文章的定时发布", e);
        }
        logger.info("任务完成：文章的定时发布");
    }
}
